package com.atguigu.sparkcore.day01.singlevalue

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}
import org.json4s.scalap.scalasig.ClassInfoType

import scala.reflect.ClassTag

/**
 * Author atguigu
 * Date 2020/10/27 16:38
 */
object SortByDemo {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("SortByDemo").setMaster("local[2]")
        val sc: SparkContext = new SparkContext(conf)
        /*val list1 = List(30, 50, 70, 60, 10, 20)
        val rdd1: RDD[Int] = sc.parallelize(list1, 2)
        //部分应用
        val rdd2: RDD[Int] = rdd1.sortBy(x => -x, true)*/
        
        val list1 = List("abc", "aa", "ccc", "abcd", "zzz")
//        val list2 = list1.sortBy(s => (s.length, s))(Ordering.Tuple2(Ordering.Int, Ordering.String.reverse))
//        println(list2)
        
        val rdd1= sc.parallelize(list1, 2)
        //Ordering
        val rdd2 = rdd1
            .sortBy(s => (s.length, s), true)(Ordering.Tuple2(Ordering.Int, Ordering.String.reverse), implicitly[ClassTag[(Int, String)]])
        
        rdd2.collect.foreach(println)
        
        sc.stop()
        
    }
}
